<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>短信平台</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" th:href="@{/vendor/bootstrap/css/bootstrap.min.css}">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet"  th:href="@{/vendor/font-awesome/css/font-awesome.css}">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" th:href="@{/css/fontastic.css}">
    <!-- Google fonts - Roboto -->
    <!--<link rel="stylesheet" th:href="@{https://fonts.googleapis.com/css?family=Roboto:300,400,500,700}">-->
    <!-- jQuery Circle-->
    <link rel="stylesheet" th:href="@{/css/grasp_mobile_progress_circle-1.0.0.min.css}">
    <!-- Custom Scrollbar-->
    <link rel="stylesheet" th:href="@{/vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css}">
    <!-- theme stylesheet-->
    <link rel="stylesheet" th:href="@{/css/style.blue.css}" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" th:href="@{/css/custom.css}">
    <!-- Favicon-->
    <link rel="shortcut icon" th:href="@{/img/favicon.ico}">
    <!--toastr-->
    <link rel="stylesheet" th:href="@{/css/toastr.css}">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
</head>
<style>
    input.error { border: 1px solid red; }
    label.error {
        font-weight: bold;
        color: red;
    }

</style>
<!-- JavaScript files-->
<script type="text/javascript" th:src="@{/js/jquery.js}" ></script>
<script type="text/javascript" th:src="@{/vendor/popper.js/umd/popper.min.js}"> </script>
<script th:src="@{/vendor/bootstrap/js/bootstrap.min.js}"></script>
<script th:src="@{/js/grasp_mobile_progress_circle-1.0.0.min.js}"></script>
<script th:src="@{/vendor/jquery.cookie/jquery.cookie.js}"> </script>
<script th:src="@{/vendor/chart.js/Chart.min.js}"></script>
<script th:src="@{/vendor/jquery-validation/jquery.validate.min.js}"></script>
<script th:src="@{/js/jquery-validation/jquery.validate.min.js}"></script>
<script th:src="@{/vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js}"></script>
<script th:src="@{/js/bootstrapValidator.min.js}"></script>
<script th:src="@{/js/toastr.min.js}"></script>
<script th:src="@{/js/base.js}"></script>
<!-- Main File-->
<script th:src="@{/js/front.js}"></script>
<meta name="_csrf" th:content="${_csrf.token}"/>
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
<body>
<!-- Side Navbar -->
<div th:replace="~{/pages/common/side_navbar.html}"></div>

<div class="page">
    <!-- navbar-->
    <div th:replace="~{/pages/common/header_navbar.html}"></div>
    <!-- Breadcrumb-->
    <div class="breadcrumb-holder">
        <div class="container-fluid">
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="#">角色管理</a></li>
                <li class="breadcrumb-item active">角色信息</li>
            </ul>
        </div>
    </div>
    <!--新增用户div start -->
    <section class="forms">
        <div class="container-fluid">
            <div class="col-lg-12 mt-3">
                <div class="card">
                    <div class="card-header d-flex align-items-center" th:if="${null == role.id}">
                        <h4>新增</h4>
                    </div>
                    <div class="card-header d-flex align-items-center" th:if="${null != role.id}">
                        <h4>编辑</h4>
                    </div>

                    <!--数据字段-->
                    <div class="card-body">
                        <form class="form-horizontal" >
                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">角色名称  <em style="color: red;">*</em></label>
                                <div class="col-sm-4">
                                    <input type="hidden" th:value="${role.id}" name="id" class="roleId"/>
                                    <input type="text" placeholder="" th:value="${role.roleDesc}"
                                           name="roleDesc" id="roleDesc" class="form-control" />
                                </div>
                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">角色代码  </label>
                                <div class="col-sm-4">
                                    <input type="text" placeholder="必须以ROLE_开头" name="roleName" id="roleName"
                                           th:value="${role.roleName}"  class="form-control" />
                                </div>
                            </div>
                            <div class="line"></div>

                            <div class="form-group row">
                                <label class="col-sm-2 form-control-label">备注 </label>
                                <div class="col-sm-4">
                                    <textarea type="text" class="form-control" name="roleRemark" id="roleRemark"
                                              th:text="${role.roleRemark}"  rows="3">

                                    </textarea>
                                </div>
                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <div class="col-sm-4 offset-sm-2">
                                    <a th:href="@{/sys/role/list}" class="btn btn-secondary ml-1">返回</a>
                                    <input type="submit" class="btn btn-success ml-5 roleSubmit" value="保存"/>
                                </div>
                                <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" th:if="${_csrf}"/>
                            </div>
                        </form>
                    </div>
                </div>
            </div>

        </div>
    </section>
    <!--新增用户div end -->
</div>

</body>
<script type="text/javascript">

    //表单验证
    $(function () {

        toastr.options = {
            closeButton: false, //是否显示关闭按钮（提示框右上角关闭按钮）；
            debug: false, //是否为调试；
            progressBar: false, //是否显示进度条（设置关闭的超时时间进度条）
            positionClass: "toast-top-center", //消息框在页面显示的位置
            onclick: null, //点击消息框自定义事件
            showDuration: "300", //显示动作时间
            hideDuration: "1000", //隐藏动作时间
            timeOut: "2000", //自动关闭超时时间
            extendedTimeOut: "1000",
            showEasing: "swing",
            hideEasing: "linear",
            showMethod: "fadeIn",
            hideMethod: "fadeOut"
        };
        $('form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                roleDesc: {
                    message: '角色名验证失败',
                    validators: {
                        notEmpty: {
                            message: '角色名不能为空'
                        }
                    }
                }

            }

        })
        .on('success.form.bv', function (e) {
            e.preventDefault();
            var data = {};
            data.id = $(".roleId").val();
            data.roleDesc =  $("#roleDesc").val();
            data.roleName =  $("#roleName").val();
            data.roleRemark = $("#roleRemark").val();
            $.requestJsonAjax({
                    url: $appName+"/api/role/save",
                    type: "post",
                    data: data,
                    success: function (result) {
                       // console.log("返回结果："+result)
                        if (result.success) {
                            toastr.success(result.msg);
                            setTimeout(function(){
                                window.location.href=$appName+"/sys/role/list";
                            },1500)
                        }else{
                            toastr.error(result.msg);
                            $(".roleSubmit").attr("disabled",false)
                        }

                    }
                }
            )

        });
    })

</script>
</html>